package server.gui;

import server.LogException;

/**
 * <h1>Class ScreenRefresh</h1>
 * 
 * This thread periodically refreshes the main screen. It updates the text
 * report and the graphics.
 * 
 * @author Tomas
 * @date March 10 2009
 */
public class ScreenRefresh extends Thread{

	protected boolean finished;
	protected ServerMainView parent = null;
	
	/**
	 * Initializes the thread.
	 * 
	 * @param p
	 * 		Window to be refreshed.
	 */
	public ScreenRefresh(ServerMainView p){
		
		parent = p;
		finished = false;
		
	}
	
	/**
	 * Thread main loop.
	 */
	public void run(){
		
		while(!finished){
			
			parent.updateStatistics();
			
			try{
				// We'll refresh every 5 seconds.
				Thread.sleep(5000);
			}catch(Exception e){
				LogException.getInstance().logException(e);
			}
			
		}
		
	}
	
	/**
	 * Stops the thread.
	 */
	public void finish(){
		
		finished = true;
		
	}
}
